package com.jinxiangyang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jinxiangyang.domain.Video;
import com.jinxiangyang.mapper.VideoMapper;
import com.jinxiangyang.service.VideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author jinxiangyang
 * @since 2023-08-12
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {

    @Autowired
    private VideoMapper videoMapper;

    @Override
    public  Map<String,Object> getListVideoPage(Integer pageNumber, Integer pageSize, Video video) {
        Page<Video> videoPage = new Page<>(pageNumber,pageSize);
        List<Video> videoPageByCourse = videoMapper.getVideoPageByCourse(videoPage,video);
        Map<String,Object> map = new HashMap<>();
        map.put("data",videoPageByCourse);
        map.put("page",videoPage);
        return map;
    }

    @Override
    public void removeVideoCourseId(Long id) {
        LambdaQueryWrapper<Video> wrap = new LambdaQueryWrapper();
        wrap.eq(Video::getCourseId,id);
        baseMapper.delete(wrap);
    }
}
